package com.finalab.website.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.finalab.website.dao.GraduateMapper;
import com.finalab.website.dao.po.GraduatePO;
import com.finalab.website.model.Graduate;
import com.finalab.website.service.GraduateService;

@Service
public class GraduateServiceImpl implements GraduateService {

	@Autowired
	private GraduateMapper mapper;
	
	@Override
	public Graduate selectById(int id) {
		GraduatePO po = mapper.selectByPrimaryKey(id);
		Graduate graduate = new Graduate();
		BeanUtils.copyProperties(po, graduate);
		return graduate;
	}

	@Override
	public List<Graduate> selectAll(){
		List<Graduate> graduates = new ArrayList<>();
		for(GraduatePO po : mapper.selectAll()) {
			Graduate g = new Graduate();
			BeanUtils.copyProperties(po, g);
			graduates.add(g);
		}
		return graduates;
	}
	
	@Override
	public void insert(Graduate graduate) {
		GraduatePO po = new GraduatePO();
		BeanUtils.copyProperties(graduate, po);
		mapper.insertSelective(po);
	}

	@Override
	public void delete(int id) {
		mapper.deleteByPrimaryKey(id);
	}

	@Override
	public void update(Graduate graduate) {
		GraduatePO po = new GraduatePO();
		BeanUtils.copyProperties(graduate, po);
		mapper.updateByPrimaryKeySelective(po);
	}

}
